//
//  SAPaperSetTableViewCell.m
//  saasRetail
//
//  Created by 黄志刚 on 2022/5/13.
//

#import "SAPaperSetTableViewCell.h"
#import "SAPaperSetModel.h"

@interface SAPaperSetTableViewCell ()

@property (nonatomic, strong) UIButton *selectBtn;
@property (nonatomic, strong) UIImageView *imageV;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *contentLab;
@property (nonatomic, strong) UIView *line;
@property (nonatomic, strong) UIButton *rightBtn;

@end

@implementation SAPaperSetTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initUI];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

-(void)setModel:(SAPaperSetModel *)model {
    _model = model;
    self.titleLab.text = model.titleStr;
    self.selectBtn.selected = model.isSelect;
}

#pragma mark - event
-(void)clickedSelectBtn {
    self.model.isSelect = !self.model.isSelect;
    self.selectBtn.selected = self.model.isSelect;
}

-(void)clickedRightBtn {
    !self.rightBlock ?: self.rightBlock();
}

#pragma mark - initUI
-(void)initUI {
    self.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.selectBtn];
//    [self.contentView addSubview:self.imageV];
    [self.contentView addSubview:self.titleLab];
//    [self.contentView addSubview:self.contentLab];
//    [self.contentView addSubview:self.rightBtn];
    [self.contentView addSubview:self.line];
}

-(UIButton *)selectBtn {
    if (!_selectBtn) {
        _selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _selectBtn.frame = SARectMake(0, 0, 60, 45);
        [_selectBtn setImage:[UIImage imageNamed:@"shop_blueRound2"] forState:UIControlStateNormal];
        [_selectBtn setImage:[UIImage imageNamed:@"shop_blueCheck2"] forState:UIControlStateSelected];
        [_selectBtn addTarget:self action:@selector(clickedSelectBtn) forControlEvents:UIControlEventTouchUpInside];
    }
    return _selectBtn;
}

-(UIImageView *)imageV {
    if (!_imageV) {
        _imageV = [[UIImageView alloc] initWithFrame:SARectMake(kBaseScreenWidth - 30, 11, 23, 23)];
        _imageV.image = [UIImage imageNamed:@"pay_arrow_right2"];
        _imageV.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _imageV;
}

-(UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] initWithFrame:SARectMake(60, 0, 100, 45)];
        _titleLab.textColor = kBlackColor;
        _titleLab.font = kFont(16);
    }
    return _titleLab;
}

-(UILabel *)contentLab {
    if (!_contentLab) {
        _contentLab = [[UILabel alloc] initWithFrame:SARectMake(kBaseScreenWidth - 137, 0, 100, 45)];
        _contentLab.textColor = kBlackColor;
        _contentLab.font = kFont(16);
        _contentLab.textAlignment = NSTextAlignmentRight;
    }
    return _contentLab;
}

-(UIButton *)rightBtn {
    if (!_rightBtn) {
        _rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _rightBtn.frame = SARectMake(kBaseScreenWidth - 250, 0, 250, 45);
        [_rightBtn addTarget:self action:@selector(clickedRightBtn) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rightBtn;
}


-(UIView *)line {
    if (!_line) {
        _line = [[UIView alloc] initWithFrame:SARectMake(0, 45, kBaseScreenWidth, 1)];
        _line.backgroundColor = kLineColor;
    }
    return _line;
}

@end
